#博客注册页面
import time
import os
from selenium.webdriver.common.by import By

from common.Utils import ForumDriver


class Forumsign:
    url=""
    def __init__(self):
        self.url="http://127.0.0.1:58080/sign-up.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)
    #成功注册
    def SignupSucText(self):
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("o读")
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").send_keys("七")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        time.sleep(2)
        #查找用户登录，有注册成功

        ForumDriver.getScreenshot()
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        self.driver.back()
        #注册失败：
    def SignInFaiText(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        checkbox_selment = self.driver.find_element(By.CSS_SELECTOR, "#policy")
        if checkbox_selment.is_selected():
            checkbox_selment.click()
        time.sleep(2)
        ForumDriver.getScreenshot()
        print("输入用户名，其他不输入")
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
       # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        ForumDriver.getScreenshot()
        #是否出现提示
        tex1=self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(3) > div").text
        print(tex1)
        assert tex1=="昵称不能为空"
        tex2=self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(4) > div > div").text
        print(tex2)
        assert tex2=="密码不能为空"
        tex3=self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(5) > div > div").text
        print(tex3)
        assert tex3=="请检查确认密码"
        time.sleep(2)

        print("不输入用户名，输入昵称，不输入密码，输入确认密码，不勾选")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("123")

        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("3")
        # self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        checkbox_selment=self.driver.find_element(By.CSS_SELECTOR,"#policy")
        if checkbox_selment.is_selected():
            checkbox_selment.click()
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        ForumDriver.getScreenshot()
        # 是否出现提示
        tex = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(2) > div").text
        print(tex1)
        assert tex=="用户名不能为空"
        tex0 = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(4) > div > div").text
        print(tex2)
        assert tex0=="密码不能为空"
        text = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(5) > div > div").text
        print(tex3)
        assert text=="请检查确认密码"

        print("不输入用户名，不输入昵称，输入密码，不输入确认密码，勾选同意方框")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")

        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()

        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

        time.sleep(2)
        ForumDriver.getScreenshot()
        # 是否出现提示
        t1 = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(2) > div").text
        print(t1)
        assert t1=="用户名不能为空"
        t2 = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(3) > div").text
        print(t2)
        assert t2=="昵称不能为空"
        t3 = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(5) > div > div").text
        print(t3)
        assert t3=="请检查确认密码"

        print("输入用户名，输入昵称，输入密码，不输入确认密码，不勾选同意方框")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("nic")

        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")

        checkbox_selment = self.driver.find_element(By.CSS_SELECTOR, "#policy")
        if checkbox_selment.is_selected():
            checkbox_selment.click()
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        ForumDriver.getScreenshot()
        # 是否出现提示
        te3 = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(5) > div > div").text
        print(t3)
        assert t3 == "请检查确认密码"


        print("输入用户名，不输入昵称，不输入密码，输入确认密码，不勾选同意方框")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("123")

        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("swdd")
        checkbox_selment = self.driver.find_element(By.CSS_SELECTOR, "#policy")
        if checkbox_selment.is_selected():
            checkbox_selment.click()
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        ForumDriver.getScreenshot()
        # 是否出现提示
        ta1 = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(3) > div").text
        print(ta1)
        assert ta1 == "昵称不能为空"
        ta2 = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(4) > div > div").text
        print(ta2)
        assert ta2 == "密码不能为空"


        print("输入重复用户名，输入昵称，输入密码，输入确认密码，勾选同意方框")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("读")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("ddd")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("swdd")

        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("swdd")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()

        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
    #是否出现警告弹窗，用户名重复
        ForumDriver.getScreenshot()


        print("输入用户名，输入昵称，输入密码，输入确认密码，勾选同意方框,确认密码和密码不一致")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("读")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("ddd")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("swdd")

        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("sdd")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()

        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        ForumDriver.getScreenshot()
        t=self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(5) > div > div").text
        print(t)
        assert  t=="请检查确认密码"

    def SignInJopText(self):
        self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(6) > label > span > a").click()
        # 是否跳转到协议内容界面
        ForumDriver.getScreenshot()
        time.sleep(1)

        self.driver.find_element(By.CSS_SELECTOR, "body > div.page.page-center > div > div.text-center.text-muted.mt-3 > a").click()
        #是否跳转到用户登录界面
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        ForumDriver.getScreenshot()
        time.sleep(1)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR,"#password_a > svg").click()
        #截图是否明文显示
        ForumDriver.getScreenshot()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat_a > svg").click()
        # 截图是否明文显示
        ForumDriver.getScreenshot()


